# -*- coding: utf-8 -*-
'''
@author: lowzoom
'''
import os
import cfg
import main
import shutil

# 开场动画文件名
BOOTFLOW_IN_FILENAME = 'bootflowintro_MARKER.vp6'
BOOTFLOW_OUT_FILENAME = 'bootflowoutro.vp6'

# 超过这个大小表示还没优化
SIZE_LIMIT = 50000

def is_skip():
	return (os.path.getsize(os.path.join(
						cfg.pref[cfg.MOVIE_PATH],
						BOOTFLOW_IN_FILENAME))) < SIZE_LIMIT and \
				(os.path.getsize(os.path.join(
						cfg.pref[cfg.MOVIE_PATH],
						BOOTFLOW_OUT_FILENAME))) < SIZE_LIMIT

def set_skip(skip):
	if is_skip() == skip:
		return

	bootflow_in_path = os.path.join(cfg.pref[cfg.MOVIE_PATH], BOOTFLOW_IN_FILENAME)
	bootflow_out_path = os.path.join(cfg.pref[cfg.MOVIE_PATH], BOOTFLOW_OUT_FILENAME)

	bootflow_in_bak_path = '.'.join((bootflow_in_path, main.__author__))
	bootflow_out_bak_path = '.'.join((bootflow_out_path, main.__author__))

	if skip:
		os.rename(bootflow_in_path, bootflow_in_bak_path)
		os.rename(bootflow_out_path, bootflow_out_bak_path)

		stub_movie_path = os.path.join(main.base_path, 'data', 'stub_mov')
		shutil.copyfile(stub_movie_path, bootflow_in_path)
		shutil.copyfile(stub_movie_path, bootflow_out_path)
	else:
		os.remove(bootflow_in_path)
		os.remove(bootflow_out_path)
		
		os.rename(bootflow_in_bak_path, bootflow_in_path)
		os.rename(bootflow_out_bak_path, bootflow_out_path)
		

if __name__ == '__main__':
	main.base_path = os.path.dirname(main.base_path)

#	cfg.set_game_path(r'E:\Game\FIFA.12\FIFA.12.RUS_EPIDEMZ.NET\Game')
	cfg.set_game_path(r'C:\Users\lowzoom\Desktop\fuck\1\game')

	skip = is_skip()
	print(skip)
	set_skip(skip)
